<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="pizza.admin.entity.User"%>
<%@ page import="pizza.admin.entity.Order"%>
<%
	User adminUser = null;
	
	if (session.getAttribute("user") != null) {
		adminUser = (User) session.getAttribute("user");
	}

	if (adminUser == null) {
		response.sendRedirect("/");
	}
	
	Order order = new Order();

	if(request.getAttribute("order")!=null) {
		order = (Order) request.getAttribute("order");
	}
%>
<jsp:include page="../../layout/header.jsp" flush="true" />
<div class="container">

	<h3>Orders</h3>
	<div class="main row-fluid">
		
		<%if(request.getMethod()=="POST"&&!order.validateForDB()){ %>
        	<div class="alert alert-error">All fields with * are required !</div>
        <% }%>
		<span class="span12 ">
			<form name='' method='post' action=''>
				<label class="control-label" for="inputAddress">Address *</label>
				
				<div class="controls">
					<input name="address" type="text" id="inputAddress"
						value='<%=order.getAddress()%>'>
				</div>
				
				<label class="control-label" for="inputPhone">Phone *</label>
				<div class="controls">
					<input name="phone" type="text" id="inputPhone"
						value='<%=order.getPhone()%>'>
				</div>
				
				<label class="control-label" for="inputDescription">User*: </label>
				<div class="controls">
					<select name="user" id="inputDescription">
						<%
						Collection<User> allUsers = (Collection<User>)request.getAttribute("users");
						
						if(allUsers!=null&&allUsers.size()>0){
							Iterator objectsIterator = allUsers.iterator();
							while ( objectsIterator.hasNext() ) {
								User user = (User)objectsIterator.next();
						%>
							<option value='<%= user.getId().toString()%>' <%=(user.getId()==order.getUser().getId())?"selected=selected":""%>><%= user.getName()+" "+user.getSurname()%></option>
						<%
							}
						}
						%>
					</select>
				</div>
				
				<label class="control-label" for="inputDescription">Description </label>
				<div class="controls">
					<input name="description" type="text" id="inputDescription"
						value='<%=order.getDescription()%>'>
				</div>
				
				
				
				<div class="controls">
					<br>
					<input type="submit" name="submit" id="submit" value='Save'
						class='btn btn-primary'>
				</div>
			</form>
		</span>
	</div>
</div>
<!-- /container -->

<jsp:include page="../../layout/footer.jsp" flush="true" />